'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url admin/dls/kh/index2/index2 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			_id,
			type
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		if (type == "getgg") {
			if (userInfo.role.includes("admin")) {
				res.notices = await db.collection('b_notices_manage').orderBy('istop', 'desc').get()
			}

			if (userInfo.role.includes("agent")) {
				res.notices = await db.collection('b_notices_manage').where({
					lookrole: _.in(['agent'])
				}).orderBy('istop', 'desc').get()
			}

			if (userInfo.role.includes("middleman")) {
				res.notices = await db.collection('b_notices_manage').where({
					lookrole: _.in(['middleman'])
				}).orderBy('istop', 'desc').get()
			}

		}

		if (type == "update_read") {
			console.log("_id=>", _id);
			let user_id = userInfo._id;
			let update1 = await db.collection('b_notices_manage').where({
				_id: _id
			}).update({
				isread: _.push(user_id)
			})
		}

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
